package com.pet.server.ext.action.find;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.data.Page;
import com.pet.server.ext.data.PetSay;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;

public class Petsay extends ActionBase{

	public Integer startIndex,itemCount;
	public String queryString;
	public String pet_cate;
	public Page page;
	public Petsay(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		startIndex = NumberUtil.getInteger(params.getFieldValue("startIndex"), 0);
		itemCount =  NumberUtil.getInteger(params.getFieldValue("itemCount"), 10);
		queryString = params.getFieldValue("queryString");
		pet_cate = params.getFieldValue("pet_cate");
		page = new Page(startIndex, itemCount,queryString);
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		
		userService.searchPetSay(page, pet_cate, BaseAttribute.LOGIC_TRUE);
		JSONArray array = new JSONArray();
		for(PetSay ps:(java.util.List<PetSay>)page.getList()){
			JSONObject o = new JSONObject();
			o.put("id", ps.id);
			//o.put("create_time", JsonUtil.getTime(ps.create_time));
			o.put("title", ps.title);
			o.put("source", ps.source);
		    array.add(o);
		}
		Result result = new Result();
        //result.put("data", o);
        //result.setPage(page,"text","image0","image1","image2","ico_path");
	    result.setPage4array(page, array);
		return result;
	}


}
